const mysql = require("mysql");

const conn = mysql.createConnection({
    host: "127.0.0.1",
    user: "root",
    password: "",
    database: "mimile",
    port: 3306
});

conn.connect(function (err) {
    if (err) {
        console.log("链接失败:" + err.message);
    }
});
function exec(sql, params, callback) {
    conn.query(sql, params, (err, result, fields) => {
        callback(err, result, fields);
    })
}

function execAsync(sql, params) {
    return new Promise((resolve, reject) => {
        conn.query(sql, params, (err, result, fields) => {
            if (err) {
                reject(err, result, fields);
                return;
            }
            resolve(err, result, fields);
        })
    })
}

module.exports = {
    exec,
    execAsync
}